package org.jeecgframework.web.service.impl;
import java.io.Serializable;
import java.util.List;
import java.util.UUID;

import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
import org.jeecgframework.web.service.ZyCinemaServiceI;
import org.jeecgframework.web.system.pojo.base.TSTerritory;
import org.jeecgframework.web.system.pojo.base.ZyCinemaEntity;
import org.jeecgframework.web.system.pojo.base.ZyEquipmentSpareEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**   
 * @Title: ZyCinemaServiceImpl
 * @Description: 影院信息
 * @author ZhangYunlong
 * @date 2016-04-01
 * @version V1.0   
 *
 */
@Service("zyCinemaService")
@Transactional
public class ZyCinemaServiceImpl extends CommonServiceImpl implements ZyCinemaServiceI {

	
 	public <T> void delete(T entity) {
 		super.delete(entity);
 		//执行删除操作配置的sql增强
		this.doDelSql((ZyCinemaEntity)entity);
 	}
 	
 	public <T> Serializable save(T entity) {
 		Serializable t = super.save(entity);
 		//执行新增操作配置的sql增强
// 		this.doAddSql((ZyCinemaEntity)entity);
 		return t;
 	}
 	
 	public <T> void saveOrUpdate(T entity) {
 		super.saveOrUpdate(entity);
 		//执行更新操作配置的sql增强
// 		this.doUpdateSql((ZyCinemaEntity)entity);
 	}
 	
 	/**
	 * 默认按钮-sql增强-新增操作
	 * @param id
	 * @return
	 */
 	public boolean doAddSql(ZyCinemaEntity t){
	 	return true;
 	}
 	/**
	 * 默认按钮-sql增强-更新操作
	 * @param id
	 * @return
	 */
 	public boolean doUpdateSql(ZyCinemaEntity t){
	 	return true;
 	}
 	/**
	 * 默认按钮-sql增强-删除操作
	 * @param id
	 * @return
	 */
 	public boolean doDelSql(ZyCinemaEntity t){
	 	return true;
 	}
 	
 	/**
	 * 替换sql中的变量
	 * @param sql
	 * @return
	 */
 	public String replaceVal(String sql,ZyCinemaEntity t){
 		sql  = sql.replace("#{id}",String.valueOf(t.getId()));
 		sql  = sql.replace("#{code}",String.valueOf(t.getCode()));
 		sql  = sql.replace("#{name}",String.valueOf(t.getName()));
 		sql  = sql.replace("#{ename}",String.valueOf(t.getEname()));
 		sql  = sql.replace("#{spread_name}",String.valueOf(t.getSpreadName()));
 		sql  = sql.replace("#{address}",String.valueOf(t.getAddress()));
 		sql  = sql.replace("#{room}",String.valueOf(t.getRoom()));
 		sql  = sql.replace("#{is_tms}",String.valueOf(t.getIsTms()));
 		sql  = sql.replace("#{is_normal}",String.valueOf(t.getIsNormal()));
 		sql  = sql.replace("#{exception_reason}",String.valueOf(t.getExceptionReason()));
 		sql  = sql.replace("#{phone}",String.valueOf(t.getPhone()));
 		sql  = sql.replace("#{fax}",String.valueOf(t.getFax()));
 		sql  = sql.replace("#{province}",String.valueOf(t.getProvince()));
 		sql  = sql.replace("#{city}",String.valueOf(t.getCity()));
 		sql  = sql.replace("#{latitude}",String.valueOf(t.getLatitude()));
 		sql  = sql.replace("#{bp_no}",String.valueOf(t.getBpNo()));
 		sql  = sql.replace("#{business}",String.valueOf(t.getBusiness()));
 		sql  = sql.replace("#{is_noc}",String.valueOf(t.getIsNoc()));
 		sql  = sql.replace("#{is_service}",String.valueOf(t.getIsService()));
 		sql  = sql.replace("#{create_name}",String.valueOf(t.getCreateName()));
 		sql  = sql.replace("#{create_by}",String.valueOf(t.getCreateBy()));
 		sql  = sql.replace("#{create_date}",String.valueOf(t.getCreateDate()));
 		sql  = sql.replace("#{update_name}",String.valueOf(t.getUpdateName()));
 		sql  = sql.replace("#{update_by}",String.valueOf(t.getUpdateBy()));
 		sql  = sql.replace("#{update_date}",String.valueOf(t.getUpdateDate()));
 		sql  = sql.replace("#{UUID}",UUID.randomUUID().toString());
 		return sql;
 	}

	@Override
	public void updateEsOfCm(ZyCinemaEntity cm) {
		List<ZyEquipmentSpareEntity> esList = super.findHql("from ZyEquipmentSpareEntity where zyCinema.id = ?", cm.getId());
		for (ZyEquipmentSpareEntity es : esList) {
			es.setTsTerritory(cm.getProvince());
			super.saveOrUpdate(es);
		}
	}
}